<html>
<head>
	<meta charset="UTF-8">
    <title>Web sockets test</title>
    <script src="jquery-min.js" type="text/javascript"></script>
    <script type="text/javascript">
        var ws;
        function ToggleConnectionClicked() {          
                try {
                    ws = new WebSocket("ws://localhost:8080/tx-test");//连接服务器		
					
					ws.onopen = function(event){alert("connected server \r\n status ："+this.readyState);};
					ws.onmessage = function(event){alert("receive data ：\r\n"+event.data);};
					ws.onclose = function(event){alert("close connection from server \r\n status："+this.readyState);};
					ws.onerror = function(event){alert("WebSocket exception！");};
                } catch (ex) {
                    alert(ex.message);      
				}
        };
 
        function SendData() {
			try{
				ws.send("beston");
			}catch(ex){
				alert(ex.message);
			}
        };
 
		function seestate(){
			alert(ws.readyState);
		}
       
    </script>
</head>
<body>
   <button id='ToggleConnection' type="button" onclick='ToggleConnectionClicked();'>connectServer</button><br /><br />
    <button id='ToggleConnection' type="button" onclick='SendData();'>send my name:beston</button><br /><br />
    <button id='ToggleConnection' type="button" onclick='seestate();'>show status</button><br /><br />
</body>
</html>